<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<title>角色管理</title>
<style type="text/css">
html,body {
	margin: 0;
	padding: 0;
	border: 0;
	width: 100%;
	height: 100%;
}
</style>
<script src="../scripts/boot.js" type="text/javascript"></script>
</head>

<body style="display:none;">
	<div class="mini-toolbar">
		<a class="mini-button" plain="true" onclick="add" iconcls="icon-add">新增</a>
		<a class="mini-button" plain="true" onclick="edit" iconcls="icon-edit">编辑</a>
		<a class="mini-button" plain="true" onclick="deleteRows" iconcls="icon-remove">删除</a>
		<a class="mini-button" plain="true" onclick="itemSetting" iconcls="icon-user">编辑权限</a>
	</div>
	<div class="mini-fit">
		<div id="datagrid1" class="mini-datagrid"
			style="width:100%;height:100%;"  treeColumn="name" 
			url="listData" idField="id" parentField="fid" multiSelect="false" resultAsTree="false" allowResize="true" expandOnLoad="true">
			<div property="columns">
				<div type="indexcolumn"></div>
				<div name="text" field="name" width="200" headerAlign="center" allowSort="true">角色名称</div>
			</div>
		</div>		
	</div>
	<script type="text/javascript">
		var basepath = window.location.pathname + "/../";
		$(function() {
			//加载全部级别
			$("body").show(); //显示
		});
		mini.parse();
		var grid = mini.get("datagrid1");
		grid.load();
		grid.sortBy("id", "asc");

		function add() {
			mini.open({
				url : basepath+"add",
				title : "新增角色",
				width : 400,
				height : 300,
				iconCls : "icon-add",
				showMaxButton : true,
				onload : function() {
					// var iframe = this.getIFrameEl();
					// var data = { action: "new" };
					// iframe.contentWindow.SetData(data);
				},
				ondestroy : function(action) {
					grid.reload();
				}
			});
		}
		function itemSetting(id){
			var row = grid.getSelected();
			if(row == null){
				mini.alert("请选择一条记录");
				return;
			}
			mini.open({
				url : basepath+"moduleRole?roleId="+row.id,
				title : "修改角色信息",
				width : 600,
				height : 600,
				iconCls : "icon-edit",
				showMaxButton : true,
				onload : function() {
				},
				ondestroy : function(action) {
					//grid.reload();
				}
			});
		}
		function edit() {
			var row = grid.getSelected();
			if(row == null){
				mini.alert("请选择一条记录");
				return;
			}
			mini.open({
				url : basepath+"edit",
				title : "修改角色信息",
				width : 400,
				height : 300,
				iconCls : "icon-edit",
				showMaxButton : true,
				onload : function() {
					var iframe = this.getIFrameEl();
					iframe.contentWindow.SetData(row);
				},
				ondestroy : function(action) {
					grid.reload();
				}
			});
		}
		function deleteRows() {
			var rows = grid.getSelecteds();
			if (rows.length > 0) {
				if (confirm("确定删除选中记录？")) {
					var ids = [];
					for ( var i = 0, l = rows.length; i < l; i++) {
						var r = rows[i];
						ids.push(r.id);
					}
					var id = ids.join(',');
					grid.loading("操作中，请稍候......");
					$.ajax({
						url : "remove",
						data : {
							id : id
						},
						success : function(text) {
							grid.reload();
						},
						error : function() {
							grid.reload();
						}
					});
				}
			} else {
				alert("请选中一条记录");
			}
		}
		function query() {
			grid.load({
				name : mini.get("queryName").getFormValue()
			});
		}
	</script>
</body>
</html>
